{extend name="base" /}
{block name="body"}
<div class="layui-card">
    <div class="layui-card-header">
        <form action="{:url('admin/ad/index')}" class="layui-form" method="get">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input name="name" type="text" placeholder="请输入广告名称" autocomplete="off" value="{:input('name')}" class="layui-input" />
                </div>
                <div class="layui-input-inline">
                    <select name="category">
                        <option value="">全部分类</option>
                        {foreach name="category" key="k" item="v"}
                        <option value="{$k}" {if condition="input('category') eq $k"}selected="selected"{/if}>{$v}[{$k}]</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-primary ajax-search"><i class="fa fa-search"></i></button>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-card-body">
        <div class="layui-btn-group">
            <a href="{:url('admin/ad/add')}" class="layui-btn"><i class="fa fa-plus-circle"></i> 添加广告</a>
        </div>
        <table class="layui-table layui-form">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>所属分类</th>
                    <th>广告图片</th>
                    <th>广告名称</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {foreach name="list" item="v" empty="$empty"}
                <tr>
                    <td>{$v.id}</td>
                    <td>{$category[$v.category]}[{$v.category}]</td>
                    <td>
                        {if empty($v['image'])}
                        <img src="__IMG__/no_image_50x50.jpg"/>
                        {else/}
                        <img src="{$v.image|resize=50,50}"/>
                        {/if}
                    </td>
                    <td>{$v.name}</td>
                    <td>
                        <input type="text" name="sort_order" value="{$v.sort_order}" autocomplete="off" class="layui-input ajax-update" data-url="{:url('admin/ad/edit', ['id' => $v.id])}">
                    </td>
                    <td>
                        <input type="checkbox" name="status" lay-skin="switch" lay-filter="*" lay-text="启用|禁用" data-url="{:url('admin/ad/edit', ['id' => $v.id])}" {if $v.status eq 1}checked="checked"{/if}>
                    </td>
                    <td>
                        <a href="{:url('admin/ad/edit', ['id' => $v.id])}" class="layui-btn layui-btn-xs layui-btn-normal"><i class="fa fa-edit"></i> 编辑</a>
                        <a href="{:url('admin/ad/del', ['id' => $v.id])}" class="layui-btn layui-btn-xs layui-btn-danger ajax-delete"><i class="fa fa-trash-o"></i> 删除</a>
                    </td>
                </tr>
                {/foreach}
            </tbody>
        </table>
        <div class="page">{$list->render()}</div>
    </div>
</div>
{/block}
